<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 7.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/ME.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/ME.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/ME.ico">
  <link rel="mask-icon" href="/images/ME.ico" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"www.zhoubencheng.com","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="Overview Github Action是持续集成&#x2F;交付(CI&#x2F;CD)的平台，允许开发者自动化构建、测试、部署项目。Github Action不仅仅是DevOps，还允许在远程仓库发生其他事件时运行工作流程。Github Action提供Ubuntu\Windows\MacOS虚拟机来运行工作流程，同时也允许开发者使用自己的数据中心服务器或云服务器来自托管运行器">
<meta property="og:type" content="article">
<meta property="og:title" content="Github_Action">
<meta property="og:url" content="http://www.zhoubencheng.com/2024/09/02/Github-Action/index.html">
<meta property="og:site_name" content="Benson&#39;s blog">
<meta property="og:description" content="Overview Github Action是持续集成&#x2F;交付(CI&#x2F;CD)的平台，允许开发者自动化构建、测试、部署项目。Github Action不仅仅是DevOps，还允许在远程仓库发生其他事件时运行工作流程。Github Action提供Ubuntu\Windows\MacOS虚拟机来运行工作流程，同时也允许开发者使用自己的数据中心服务器或云服务器来自托管运行器">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-09-02T07:47:29.000Z">
<meta property="article:modified_time" content="2024-09-12T08:02:30.632Z">
<meta property="article:author" content="Benson">
<meta property="article:tag" content="github">
<meta property="article:tag" content="git">
<meta property="article:tag" content="yaml">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://www.zhoubencheng.com/2024/09/02/Github-Action/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Github_Action | Benson's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>


<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Benson's blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">最好的安排</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/ZhouBencheng" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://www.zhoubencheng.com/2024/09/02/Github-Action/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/ME.ico">
      <meta itemprop="name" content="Benson">
      <meta itemprop="description" content="Share my thoughts with you">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Benson's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Github_Action
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2024-09-02 15:47:29" itemprop="dateCreated datePublished" datetime="2024-09-02T15:47:29+08:00">2024-09-02</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2024-09-12 16:02:30" itemprop="dateModified" datetime="2024-09-12T16:02:30+08:00">2024-09-12</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Utils/" itemprop="url" rel="index"><span itemprop="name">Utils</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="overview">Overview</h2>
<p>Github
Action是持续集成/交付(CI/CD)的平台，允许开发者自动化<strong>构建</strong>、<strong>测试</strong>、<strong>部署</strong>项目。Github
Action不仅仅是<a target="_blank" rel="noopener" href="https://learn.microsoft.com/zh-cn/devops/what-is-devops">DevOps</a>，还允许在远程仓库发生其他事件时运行工作流程。Github
Action提供<code>Ubuntu\Windows\MacOS</code>虚拟机来运行工作流程，同时也允许开发者使用自己的数据中心服务器或云服务器来自托管运行器</p>
<span id="more"></span>
<h2 id="workflow">Workflow</h2>
<p>在Github
Action中使用<code>yaml</code>文件进行配置，一个<code>.yml</code>文件代表一个工作流，该配置文件均放置于项目路径<code>.github/workflows</code>下。在持续集成中，一系列操作如<code>拉取代码</code>、<code>运行测试</code>、<code>远程登录服务器</code>、<code>项目部署</code>等称为<code>Action</code>。在Github中有官方提供的开源<code>Action</code>脚本可以直接引用，比如<a target="_blank" rel="noopener" href="https://github.com/marketplace?type=actions">官方市场</a>和<a target="_blank" rel="noopener" href="https://github.com/sdras/awesome-actions"><code>awesome actions</code></a></p>
<p>在Github Action的工作流配置文件中存在以下概念</p>
<ul>
<li><code>workflow</code>:
工作流程，一般一个<code>yaml</code>文件代表一个工作流程</li>
<li><code>job</code>: 一个工作流程由多个<code>jobs</code>构成</li>
<li><code>step</code>:
一个<code>jobs</code>中会有多个<code>steps</code>串行执行，每个<code>steps</code>由无序列表符号<code>-</code>起头</li>
<li><code>action</code>:
在一个<code>steps</code>中可以采取Github的<code>action</code>库中的脚本，依次执行一个或多个命令</li>
</ul>
<p>以下将以<code>pytorch</code>中的<code>try-merge.yml</code>工作流配置文件作为样例进行语法学习</p>
<figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">Validate</span> <span class="string">and</span> <span class="string">merge</span> <span class="string">PR</span> <span class="comment"># 定义工作流名称</span></span><br><span class="line"></span><br><span class="line"><span class="attr">on:</span> <span class="comment"># 定义工作流触发条件</span></span><br><span class="line">  <span class="attr">repository_dispatch:</span></span><br><span class="line">    <span class="attr">types:</span> [<span class="string">try-merge</span>]</span><br><span class="line"></span><br><span class="line"><span class="attr">jobs:</span> <span class="comment"># 定义workflow中的多个jobs</span></span><br><span class="line">  <span class="attr">do_merge:</span> <span class="comment"># 定义第一个jobs，名称为do_merge</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">try_merge_pr_${{</span> <span class="string">github.event.client_payload.pr_num</span> <span class="string">}}</span> <span class="comment"># 定义该job的可视化名称，在github action页面中显示</span></span><br><span class="line">    <span class="attr">runs-on:</span> <span class="string">linux.20_04.4x</span> <span class="comment"># 定义该jobs的运行环境</span></span><br><span class="line">    <span class="attr">environment:</span> <span class="string">mergebot</span></span><br><span class="line">    <span class="attr">permissions:</span></span><br><span class="line">      <span class="attr">id-token:</span> <span class="string">write</span></span><br><span class="line">    <span class="attr">env:</span></span><br><span class="line">        <span class="attr">GH_RUN_URL:</span> <span class="string">${{</span> <span class="string">github.server_url</span> <span class="string">}}/${{</span> <span class="string">github.repository</span> <span class="string">}}/actions/runs/${{</span> <span class="string">github.run_id</span> <span class="string">}}</span></span><br><span class="line">    <span class="attr">steps:</span> <span class="comment"># 定义一个jobs中的多个steps</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Checkout</span> <span class="string">repo</span> <span class="comment"># step1 Checkout</span></span><br><span class="line">        <span class="attr">id:</span> <span class="string">checkout</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">actions/checkout@v3</span> <span class="comment"># 使用actions仓库中提供的checkout脚本，版本v3</span></span><br><span class="line">        <span class="attr">with:</span> <span class="comment"># with用于向第三方action提供键值对形式的参数</span></span><br><span class="line">          <span class="attr">fetch-depth:</span> <span class="number">0</span></span><br><span class="line">          <span class="attr">token:</span> <span class="string">${{</span> <span class="string">secrets.MERGEBOT_TOKEN</span> <span class="string">}}</span></span><br><span class="line"></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Setup</span> <span class="string">Python</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">actions/setup-python@v4</span></span><br><span class="line">        <span class="attr">with:</span></span><br><span class="line">          <span class="attr">python-version:</span> <span class="string">'3.8'</span></span><br><span class="line">          <span class="attr">check-latest:</span> <span class="literal">false</span></span><br><span class="line">          <span class="attr">cache:</span> <span class="string">pip</span></span><br><span class="line">          <span class="attr">architecture:</span> <span class="string">x64</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">run:</span> <span class="string">pip</span> <span class="string">install</span> <span class="string">pyyaml==6.0</span> <span class="string">rockset==1.0.3</span></span><br><span class="line"></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Setup</span> <span class="string">committer</span> <span class="string">id</span></span><br><span class="line">        <span class="attr">run:</span> <span class="string">|</span> <span class="comment"># run: |在yaml格式中表示多行文本标识符</span></span><br><span class="line">          <span class="string">git</span> <span class="string">config</span> <span class="string">--global</span> <span class="string">user.email</span> <span class="string">"pytorchmergebot@users.noreply.github.com"</span></span><br><span class="line">          <span class="string">git</span> <span class="string">config</span> <span class="string">--global</span> <span class="string">user.name</span> <span class="string">"PyTorch MergeBot"</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Merge</span> <span class="string">PR</span></span><br><span class="line">        <span class="attr">shell:</span> <span class="string">bash</span></span><br><span class="line">        <span class="attr">env:</span></span><br><span class="line">          <span class="attr">GITHUB_TOKEN:</span> <span class="string">${{</span> <span class="string">secrets.MERGEBOT_TOKEN</span> <span class="string">}}</span></span><br><span class="line">          <span class="attr">PR_NUM:</span> <span class="string">${{</span> <span class="string">github.event.client_payload.pr_num</span> <span class="string">}}</span></span><br><span class="line">          <span class="attr">FORCE:</span> <span class="string">${{</span> <span class="string">github.event.client_payload.force}}</span></span><br><span class="line">          <span class="attr">COMMENT_ID:</span> <span class="string">${{</span> <span class="string">github.event.client_payload.comment_id</span> <span class="string">}}</span></span><br><span class="line">          <span class="attr">REBASE:</span> <span class="string">${{</span> <span class="string">github.event.client_payload.rebase</span> <span class="string">}}</span></span><br><span class="line">          <span class="attr">IGNORE_CURRENT:</span> <span class="string">${{</span> <span class="string">github.event.client_payload.ignore_current</span> <span class="string">}}</span></span><br><span class="line">          <span class="attr">ROCKSET_API_KEY:</span> <span class="string">${{</span> <span class="string">secrets.ROCKSET_API_KEY</span> <span class="string">}}</span></span><br><span class="line">          <span class="attr">DRCI_BOT_KEY:</span> <span class="string">${{</span> <span class="string">secrets.DRCI_BOT_KEY</span> <span class="string">}}</span></span><br><span class="line">          <span class="attr">GITHUB_RUN_ID:</span> <span class="string">${{</span> <span class="string">github.run_id</span> <span class="string">}}</span></span><br><span class="line">        <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          set -x # set -x表示在shell启动调试模式，在每一步命令运行之前输出相应命令</span></span><br><span class="line"><span class="string">          if [ -n "${REBASE}" ]; then</span></span><br><span class="line"><span class="string">            # attempt to rebase, if it fails then comment on the PR that it failed</span></span><br><span class="line"><span class="string">            if ! python3 .github/scripts/tryrebase.py "${PR_NUM}" --branch "${REBASE}"; then</span></span><br><span class="line"><span class="string">              python3 .github/scripts/comment_on_pr.py "${PR_NUM}" "merge"</span></span><br><span class="line"><span class="string">              exit 0</span></span><br><span class="line"><span class="string">            fi</span></span><br><span class="line"><span class="string">            git checkout main</span></span><br><span class="line"><span class="string">            git fetch -p</span></span><br><span class="line"><span class="string">            # give github some time between the push and start workflows so that Github's messages</span></span><br><span class="line"><span class="string">            # on the PR appear in chronological order (timing issues can shuffle them around)</span></span><br><span class="line"><span class="string">            sleep 60</span></span><br><span class="line"><span class="string">          fi</span></span><br><span class="line"><span class="string">          if [ -n "${FORCE}" ]; then</span></span><br><span class="line"><span class="string">            if [ -n "${COMMENT_ID}" ]; then</span></span><br><span class="line"><span class="string">              python3 .github/scripts/trymerge.py --force --comment-id "${COMMENT_ID}" "${PR_NUM}"</span></span><br><span class="line"><span class="string">            else</span></span><br><span class="line"><span class="string">              python3 .github/scripts/trymerge.py --force "${PR_NUM}"</span></span><br><span class="line"><span class="string">            fi</span></span><br><span class="line"><span class="string">          elif [ -n "${IGNORE_CURRENT}" ]; then</span></span><br><span class="line"><span class="string">            if [ -n "${COMMENT_ID}" ]; then</span></span><br><span class="line"><span class="string">              python3 .github/scripts/trymerge.py --ignore-current --comment-id "${COMMENT_ID}" "${PR_NUM}"</span></span><br><span class="line"><span class="string">            else</span></span><br><span class="line"><span class="string">              python3 .github/scripts/trymerge.py --ignore-current "${PR_NUM}"</span></span><br><span class="line"><span class="string">            fi</span></span><br><span class="line"><span class="string">          elif [ -n "${COMMENT_ID}" ]; then</span></span><br><span class="line"><span class="string">            python3 .github/scripts/trymerge.py --comment-id "${COMMENT_ID}" "${PR_NUM}"</span></span><br><span class="line"><span class="string">          else</span></span><br><span class="line"><span class="string">            python3 .github/scripts/trymerge.py "${PR_NUM}"</span></span><br><span class="line"><span class="string">          fi</span></span><br><span class="line"><span class="string"></span>      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Comment</span> <span class="string">on</span> <span class="string">Canceled</span></span><br><span class="line">        <span class="attr">if:</span> <span class="string">${{</span> <span class="string">cancelled()</span> <span class="string">&amp;&amp;</span> <span class="string">steps.checkout.outcome</span> <span class="string">==</span> <span class="string">'success'</span> <span class="string">}}</span></span><br><span class="line">        <span class="attr">continue-on-error:</span> <span class="literal">true</span></span><br><span class="line">        <span class="attr">env:</span></span><br><span class="line">          <span class="attr">GITHUB_TOKEN:</span> <span class="string">${{</span> <span class="string">secrets.MERGEBOT_TOKEN</span> <span class="string">}}</span></span><br><span class="line">          <span class="attr">PR_NUM:</span> <span class="string">${{</span> <span class="string">github.event.client_payload.pr_num</span> <span class="string">}}</span></span><br><span class="line">        <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          set -x</span></span><br><span class="line"><span class="string">          python3 .github/scripts/comment_on_pr.py "${PR_NUM}" "merge"</span></span><br><span class="line"><span class="string"></span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">configure</span> <span class="string">aws</span> <span class="string">credentials</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">aws-actions/configure-aws-credentials@v3</span></span><br><span class="line">        <span class="attr">continue-on-error:</span> <span class="literal">true</span></span><br><span class="line">        <span class="attr">with:</span></span><br><span class="line">          <span class="attr">role-to-assume:</span> <span class="string">arn:aws:iam::308535385114:role/upload_to_ossci_raw_job_status</span></span><br><span class="line">          <span class="attr">aws-region:</span> <span class="string">us-east-1</span></span><br><span class="line"></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Upload</span> <span class="string">merge</span> <span class="string">record</span> <span class="string">to</span> <span class="string">s3</span></span><br><span class="line">        <span class="attr">if:</span> <span class="string">always()</span></span><br><span class="line">        <span class="attr">continue-on-error:</span> <span class="literal">true</span></span><br><span class="line">        <span class="attr">uses:</span> <span class="string">seemethere/upload-artifact-s3@v5</span></span><br><span class="line">        <span class="attr">with:</span></span><br><span class="line">          <span class="attr">s3-bucket:</span> <span class="string">ossci-raw-job-status</span></span><br><span class="line">          <span class="attr">s3-prefix:</span> <span class="string">merges/${{</span> <span class="string">github.repository</span> <span class="string">}}/${{</span> <span class="string">github.event.client_payload.pr_num</span> <span class="string">}}/${{</span> <span class="string">github.event.client_payload.comment_id</span> <span class="string">}}/${{</span> <span class="string">github.run_id</span> <span class="string">}}</span></span><br><span class="line">          <span class="attr">path:</span> <span class="string">merge_record.json</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># We want newer merge commands to supercede old ones</span></span><br><span class="line"><span class="attr">concurrency:</span></span><br><span class="line">  <span class="attr">group:</span> <span class="string">try-merge-${{</span> <span class="string">github.event.client_payload.pr_num</span> <span class="string">}}</span></span><br><span class="line">  <span class="attr">cancel-in-progress:</span> <span class="literal">true</span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure>
<ul>
<li><p><code>${{...}}</code>上下文变量，在Github
Action脚本中，存在一些Github内置的上下文变量，在工作流执行时由Github官方服务器自动注入，用于提供访问仓库、运行时变量、安全信息等相关数据</p></li>
<li><p><code>concurrency</code>字段用于控制工作流的并发执行，避免同一工作流在同一分支或特定工作流内执行多次。在上述示例中，并发事件按<code>pr_num</code>拉取请求分组，即每个PR都有自己的并发控制，当一个PR中有多个任务出发，则只有最新的被执行</p></li>
<li><p>一个job的<code>name</code>字段旨在github
action页面中运行时展示给观察者的名称，而<code>job</code>字段下的第一层工作名称就是在整个脚本中唯一区分一个job的名称</p></li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/github/" rel="tag"><i class="fa fa-tag"></i> github</a>
              <a href="/tags/git/" rel="tag"><i class="fa fa-tag"></i> git</a>
              <a href="/tags/yaml/" rel="tag"><i class="fa fa-tag"></i> yaml</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2024/08/21/%E9%87%8F%E5%8C%96%E5%92%8C%E5%8F%8D%E9%87%8F%E5%8C%96-pytorch/" rel="prev" title="量化和反量化-pytorch">
      <i class="fa fa-chevron-left"></i> 量化和反量化-pytorch
    </a></div>
      <div class="post-nav-item">
    <a href="/2024/09/11/CMU15445-Project/" rel="next" title="CMU15445 Project">
      CMU15445 Project <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#overview"><span class="nav-number">1.</span> <span class="nav-text">Overview</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#workflow"><span class="nav-number">2.</span> <span class="nav-text">Workflow</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Benson"
      src="/images/ME.ico">
  <p class="site-author-name" itemprop="name">Benson</p>
  <div class="site-description" itemprop="description">Share my thoughts with you</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">17</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/ZhouBencheng" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;ZhouBencheng" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:zhoubencheng2022@163.com" title="E-Mail → mailto:zhoubencheng2022@163.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Benson</span>
</div>

<!--
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>
-->

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>


  <script defer src="/lib/three/three.min.js"></script>
    <script defer src="/lib/three/canvas_lines.min.js"></script>


  













<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme    : 'dark',
      logLevel : 3,
      flowchart: { curve     : 'linear' },
      gantt    : { axisFormat: '%m/%d/%Y' },
      sequence : { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>


  

  

  

</body>
</html>
